import getUser from '@/api/user';

const user = {
  state: {
    name: '',
    myPermissions: ['*'],
  },
  mutations: {
    SET_NAME: (state, name) => {
      state.name = name;
    },
    SET_PERMISSIONS: (state, permissions) => {
      state.myPermissions = permissions;
    },
  },
  actions: {
    GetUserInfo({ commit }) {
      return new Promise((resolve, reject) => {
        getUser().then((response) => {
          commit('SET_PERMISSIONS', response.data.permissions);
          commit('SET_NAME', response.data.name);
          resolve(response);
        }).catch((error) => {
          reject(error);
        });
      });
    },
  },
};

export default user;
